package com.pmsystem.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pmsystem.pojo.ElectricConsume;
import com.pmsystem.service.ElectricConsumeService;
import com.pmsystem.util.BeanUtil;

@Controller
public class ElectricConsumeController {
	
	@Autowired
	private ElectricConsumeService electricConsumeService;
	
	/**
	 * 
	 * <p>Title: addElectricConsume</p >  
	 * <p>Description: 录入电费</p >  
	 * @author 泽强
	 * @param electricConsume
	 * @return
	 */
	@RequestMapping(value="addElectricConsume",method=RequestMethod.POST)
	@ResponseBody
	public Object addElectricConsume(@RequestParam Map<String,Object> map) {
		ElectricConsume electricConsume  = BeanUtil.parserToBean(BeanUtil.mapToMapWithoutNull(map),ElectricConsume.class);
		boolean flag = electricConsumeService.addElectricConsume(electricConsume);
		if(flag) {
			return "success";
		}
		return "error";
	}
	
	/**
	 * 
	 * <p>Title: updateElectricConsume</p >  
	 * <p>Description: 修改电费</p >  
	 * @author 泽强
	 * @param electricConsume
	 * @return
	 */
	@RequestMapping(value="updateElectricConsume",method=RequestMethod.POST)
	@ResponseBody
	public Object updateElectricConsume(@RequestParam Map<String,Object> map){
		ElectricConsume electricConsume  = BeanUtil.parserToBean(BeanUtil.mapToMapWithoutNull(map),ElectricConsume.class);
		boolean flag = electricConsumeService.updateElectricConsume(electricConsume);
		if(flag) {
			return "success";
		}
		return "error";
	}
	
	/**
	 * 
	 * <p>Title: findElectricConsume</p >  
	 * <p>Description: 按一定条件查询电费</p >  
	 * @author 泽强
	 * @param map
	 * @return
	 */
	@RequestMapping(value="findElectricConsume",method=RequestMethod.GET)
	@ResponseBody
	public Object findElectricConsume(@RequestParam Map<String,Object> map) {
		List list = electricConsumeService.findElectricConsume(map);
		
		return list;

	}
}
